package com.asura.ops.sync.check.server.entity.res;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResponseBase<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private String code;

    private String msg;

    private T data;

    public ResponseBase() {
    }

    private ResponseBase(ResultCode resultCode) {
        this(resultCode, null, resultCode.getMsg());
    }

    private ResponseBase(ResultCode resultCode, String msg) {
        this(resultCode, null, msg);
    }

    private ResponseBase(ResultCode resultCode, T data) {
        this(resultCode, data, resultCode.getMsg());
    }

    private ResponseBase(ResultCode resultCode, T data, String msg) {
        this(resultCode.getCode(), data, msg);
    }

    private ResponseBase(String code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public static <T> ResponseBase<T> success() {
        return new ResponseBase<>(BaseResultCodeEnum.SUCCESS, BaseResultCodeEnum.SUCCESS.getMsg());
    }

    public static <T> ResponseBase<T> success(T data) {
        return new ResponseBase<>(BaseResultCodeEnum.SUCCESS, data);
    }

    public static <T> ResponseBase<T> success(T data, String msg) {
        return new ResponseBase<>(BaseResultCodeEnum.SUCCESS, data, msg);
    }

    public static <T> ResponseBase<T> success(String msg) {
        return new ResponseBase<>(BaseResultCodeEnum.SUCCESS, msg);
    }

    public static <T> ResponseBase<T> fail() {
        return new ResponseBase<>(BaseResultCodeEnum.FAILURE, BaseResultCodeEnum.FAILURE.getMsg());
    }

    public static <T> ResponseBase<T> fail(String msg) {
        return new ResponseBase<>(BaseResultCodeEnum.FAILURE, msg);
    }

    public static <T> ResponseBase<T> fail(String resultCode, String msg) {
        return new ResponseBase<>(resultCode, null, msg);
    }

    public static <T> ResponseBase<T> fail(ResultCode resultCode) {
        return new ResponseBase<>(resultCode);
    }

    public static <T> ResponseBase<T> fail(ResultCode resultCode, String msg) {
        return new ResponseBase<>(resultCode, msg);
    }
}